package org.file5.domain;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableProperty;
import org.springframework.web.multipart.MultipartFile;

import com.google.appengine.api.datastore.Text;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.NotSaved;

@Searchable(alias = "Article")
@Cached
public class Article extends BaseEntity {

	/**
	 *  
	 */
	private static final long serialVersionUID = -2973218475949859575L;

	@SearchableProperty(name = "name")
	private String name;

	@SearchableProperty(converter = "textConverter", name = "longDesc")
	private Text longDesc;

	@SearchableProperty(name = "tags")
	private String tags; // seperated by ","

	@SearchableProperty(name = "groupTag")
	private String groupTag; //分组标签
	public static String FIELD_NAME_GROUP_TAG="groupTag"; //must be same as the field name groupTag
	// 站内产品分类
	private Key<Category> primaryCategoryKey;
	@NotSaved
	private Category primaryCategory;

	private Key<Person> authorKey;
	@NotSaved
	private Person author;
	
	private boolean topped; // 是否置顶
	private boolean pubadv; // 是否公告

	private long commentCount;//评论票数
	private long viewCount; //浏览票数
	//表情票数，参见凤凰网
	
	// used to store fileBytes from the HTML form
	@NotSaved
	private MultipartFile multipartFile = null;


	public Article() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Key<Person> getAuthorKey() {
		return authorKey;
	}

	public void setAuthorKey(Key<Person> authorKey) {
		this.authorKey = authorKey;
	}

	public Person getAuthor() {
		return author;
	}

	public void setAuthor(Person author) {
		this.author = author;
	}

	public String getLongDesc() {
		return (longDesc == null) ? "" : longDesc.getValue();
	}

	public void setLongDesc(String longDesc) {
		this.longDesc = new Text((longDesc == null) ? "" : longDesc);
	}

	public Key<Category> getPrimaryCategoryKey() {
		return primaryCategoryKey;
	}

	public void setPrimaryCategoryKey(Key<Category> primaryCategoryKey) {
		this.primaryCategoryKey = primaryCategoryKey;
	}

	public Category getPrimaryCategory() {
		return primaryCategory;
	}

	public void setPrimaryCategory(Category primaryCategory) {
		this.primaryCategory = primaryCategory;
	}

	public MultipartFile getMultipartFile() {
		return multipartFile;
	}

	public void setMultipartFile(MultipartFile multipartFile) {
		this.multipartFile = multipartFile;
	}

	@Override
	public String getComputedMd5() {
		return super.getComputedMd5(uid,
				authorKey == null ? "" : authorKey.getName());
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public long getCommentCount() {
		return commentCount;
	}

	public void setCommentCount(long commentCount) {
		this.commentCount = commentCount;
	}

	public long getViewCount() {
		return viewCount;
	}

	public void setViewCount(long viewCount) {
		this.viewCount = viewCount;
	}

	public String getGroupTag() {
		return groupTag;
	}

	public void setGroupTag(String groupTag) {
		this.groupTag = groupTag;
	}

	public boolean isTopped() {
		return topped;
	}

	public void setTopped(boolean topped) {
		this.topped = topped;
	}

	public boolean isPubadv() {
		return pubadv;
	}

	public void setPubadv(boolean pubadv) {
		this.pubadv = pubadv;
	}


}
